package com.googlecode.animator.view.specialobjects
{
	import org.papervision3d.core.geom.Lines3D;
	import org.papervision3d.core.geom.renderables.Line3D;
	import org.papervision3d.core.geom.renderables.Vertex3D;
	import org.papervision3d.core.proto.MaterialObject3D;
	import org.papervision3d.materials.special.LineMaterial;
	import org.papervision3d.objects.primitives.Plane;

	public class PlaneOutlined extends Plane
	{
		public function PlaneOutlined(material:MaterialObject3D=null, width:Number=0, height:Number=0, segmentsW:Number=0, segmentsH:Number=0)
		{
			super(material, width, height, segmentsW, segmentsH);
			
			// since planes have no thickness when viewed edge on, they will have lines around edges.
			var lm:LineMaterial = new LineMaterial(0x909090, 1);
			var lines:Lines3D = new Lines3D(lm);
			lines.name = "outline";
			
			var vt1:Vertex3D;
			var vt2:Vertex3D;
			
			var halfWidth:Number = width / 2;
			var halfHeight:Number = height / 2;
			
			var lineOffset:int = 20;
			
			var l:Line3D;
			
			//Top and bottom
			vt1 = new Vertex3D(-halfWidth -lineOffset, halfHeight + lineOffset, 0);
			vt2 = new Vertex3D(halfWidth + lineOffset, halfHeight + lineOffset, 0);
			
			l = new Line3D(lines, lm, 4, vt1, vt2);
			
			lines.addLine(l);
			
			vt1 = new Vertex3D(-halfWidth - lineOffset, -halfHeight - lineOffset, 0);
			vt2 = new Vertex3D(halfWidth + lineOffset, -halfHeight - lineOffset, 0);
			
			l = new Line3D(lines, lm, 4, vt1, vt2);
			
			lines.addLine(l);
			
			//Sides
			vt1 = new Vertex3D(-halfWidth - lineOffset, halfHeight + lineOffset, 0);
			vt2 = new Vertex3D(-halfWidth - lineOffset, -halfHeight - lineOffset, 0);
			
			l = new Line3D(lines, lm, 4, vt1, vt2);
			
			lines.addLine(l);
			
			vt1 = new Vertex3D(halfWidth + lineOffset, halfHeight + lineOffset, 0);
			vt2 = new Vertex3D(halfWidth + lineOffset, -halfHeight - lineOffset, 0);
			
			l = new Line3D(lines, lm, 4, vt1, vt2);
			
			lines.addLine(l);
			
			this.addChild(lines);

		}
		
		protected function outlineVisible(value:Boolean):void
		{
			this.getChildByName("lines").visible = value;
		}		
	}
}